ReadOnlyPropertyDrawer.cs 662 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace ExternPropertyAttributes.Editor
  4. {
  5. [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
  6. public class ReadOnlyPropertyDrawer : PropertyDrawerBase
  7. {
  8. protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label)
  9. {
  10. return GetPropertyHeight(property);
  11. }
  12. protected override void OnGUI_Internal(Rect rect, SerializedProperty property, GUIContent label)
  13. {
  14. EditorGUI.BeginProperty(rect, label, property);
  15. using (new EditorGUI.DisabledScope(disabled: true))
  16. {
  17. EditorGUI.PropertyField(rect, property, label, true);
  18. }
  19. EditorGUI.EndProperty();
  20. }
  21. }
  22. }